package com.example.myapplication10;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.example.myapplication10.R;
public class MainActivity extends AppCompatActivity {

    private BottomNavigationView bottomNavigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bottomNavigationView = findViewById(R.id.bottom_navigation);
        bottomNavigationView.setOnNavigationItemSelectedListener(navListener);

        // 默认显示首页
        if (savedInstanceState == null) {
            startActivity(new Intent(this, HomeActivity.class));
        }
    }

    private BottomNavigationView.OnNavigationItemSelectedListener navListener =
            new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    Intent intent = null;

                    if (item.getItemId() == R.id.nav_home) {
                        intent = new Intent(MainActivity.this, HomeActivity.class);
                    } else if (item.getItemId() == R.id.nav_tests) {
                        intent = new Intent(MainActivity.this, TestsActivity.class);
                    } else if (item.getItemId() == R.id.nav_booking) {
                        intent = new Intent(MainActivity.this, BookingActivity.class);
                    } else if (item.getItemId() == R.id.nav_books) {
                        intent = new Intent(MainActivity.this, BooksActivity.class);
                    }if (item.getItemId() == R.id.nav_home) {
                        intent = new Intent(MainActivity.this, HomeActivity.class);
                    } else if (item.getItemId() == R.id.nav_tests) {
                        intent = new Intent(MainActivity.this, TestsActivity.class);
                    } else if (item.getItemId() == R.id.nav_booking) {
                        intent = new Intent(MainActivity.this, BookingActivity.class);
                    } else if (item.getItemId() == R.id.nav_books) {
                        intent = new Intent(MainActivity.this, BooksActivity.class);
                    }

                    if (intent != null) {
                        startActivity(intent);
                        overridePendingTransition(0, 0); // 移除Activity切换动画
                        return true;
                    }
                    return false;
                }
            };}


